//
//  LoginView.m
//  HeWeiZhiNeng
//
//  Created by 林建 on 17/12/2.
//  Copyright © 2017年 YanCeyMichael.github.io. All rights reserved.
//

#import "LoginView.h"

@implementation LoginView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = Color.back;
        //头视图
        self.headerView = [UIView new];
        self.headerView.backgroundColor = Color.theme;
        [self addSubview:self.headerView];
        //头像
        self.headImageView = [UIImageView new];
        self.headImageView.layer.cornerRadius = 45;
        self.headImageView.layer.masksToBounds = YES;
        self.headImageView.image = [UIImage imageNamed:@"logo"];
        [self.headerView addSubview:self.headImageView];
        //快捷登录标签
        self.quickLoginLabel = [UILabel new];
        [self.headerView addSubview:self.quickLoginLabel];
        [self CreatNewLabel:self.quickLoginLabel title:@"快捷登录" color:Color.fullBtnTitle font:Common_Font(18)];
        //账号登录标签
        self.accountLoginLabel = [UILabel new];
        [self.headerView addSubview:self.accountLoginLabel];
        [self CreatNewLabel:self.accountLoginLabel title:@"账号登录" color:Color.fullBtnTitle font:Common_Font(18)];
        //滑动视图
        self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 241, kScreenW, 120)];
        self.scrollView.backgroundColor = [UIColor whiteColor];
        self.scrollView.showsVerticalScrollIndicator = NO;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.contentSize = CGSizeMake(kScreenW*2, 120);
        self.scrollView.contentOffset = CGPointMake(0, 0);
        self.scrollView.pagingEnabled = YES;
        [self addSubview:self.scrollView];
        //快捷背景
        self.quickBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 60)];
        [self.scrollView addSubview:self.quickBackView];
        //账号背景
        self.accountBackView = [[UIView alloc]initWithFrame:CGRectMake(kScreenW, 0, kScreenW, 60)];
        [self.scrollView addSubview:self.accountBackView];
        //手机号码
        self.phoneView = [[TextField_TextView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 60) contextHidden:NO];
        [self.quickBackView addSubview:self.phoneView];
        self.phoneView.OutPutTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入你的手机号" attributes:@{NSForegroundColorAttributeName:Color.stub}];
        [self.phoneView.OutPutTF setValue:Common_Font(15) forKeyPath:@"_placeholderLabel.font"];
        self.phoneView.ContextLabel.text = @"+86";
        //验证码
        self.codeView = [[TextField_TextView alloc]initWithFrame:CGRectMake(0, 60, kScreenW, 60) contextHidden:YES];
        [self.quickBackView addSubview:self.codeView];
        self.codeView.OutPutTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入验证码" attributes:@{NSForegroundColorAttributeName:Color.stub}];
        [self.codeView.OutPutTF setValue:Common_Font(15) forKeyPath:@"_placeholderLabel.font"];
        //账号
        self.accountView = [[TextField_ImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 60) left:30 right:-30 imageLeft:15];
        [self.accountBackView addSubview:self.accountView];
        self.accountView.OutPutTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入手机号/邮箱" attributes:@{NSForegroundColorAttributeName:Color.stub}];
        [self.accountView.OutPutTF setValue:Common_Font(15) forKeyPath:@"_placeholderLabel.font"];
        self.accountView.ContextView.image = [UIImage imageNamed:@"zhanghao_shoji_youxiang"];
        //密码
        self.passwordView = [[TextField_ImageView alloc]initWithFrame:CGRectMake(0, 60, kScreenW, 60)left:30 right:-30 imageLeft:15];
        [self.accountBackView addSubview:self.passwordView];
        self.passwordView.OutPutTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入密码" attributes:@{NSForegroundColorAttributeName:Color.stub}];
        [self.passwordView.OutPutTF setValue:Common_Font(15) forKeyPath:@"_placeholderLabel.font"];
        self.passwordView.ContextView.image = [UIImage imageNamed:@"zhanghao_mima"];
        //获取验证码
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.text = @"获取验证码";
        self.timeLabel.layer.cornerRadius = 5;
        self.timeLabel.layer.masksToBounds = YES;
        self.timeLabel.userInteractionEnabled = YES;
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        self.timeLabel.font = Common_Font(15);
        self.timeLabel.textColor = Color.fullBtnTitle;
        self.timeLabel.backgroundColor = Color.selected_blue;
        [self.scrollView addSubview:self.timeLabel];
        //登录按钮
        self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [self.loginBtn setTitleColor:Color.fullBtnTitle forState:UIControlStateNormal];
        [self addSubview:self.loginBtn];
        self.loginBtn.titleLabel.font = Common_Font(15);
        self.loginBtn.backgroundColor = Color.theme;
        self.loginBtn.layer.masksToBounds = YES;
        self.loginBtn.layer.cornerRadius = 5;
        //前往箭头
        self.goRegistView = [UIImageView new];
        self.goRegistView.image = [UIImage imageNamed:@"zhanghao_zhuce"];
        [self addSubview:self.goRegistView];
        //注册
        self.goRegistLabel = [UILabel new];
        [self addSubview:self.goRegistLabel];
        [self CreatNewLabel:self.goRegistLabel title:@"注册账号" color:Color.selected_blue font:Common_Font(15)];
        //注册点击视图
        self.registTapView = [UIView new];
        [self addSubview:self.registTapView];
        //或
        self.huoLabel = [UILabel new];
        [self addSubview:self.huoLabel];
        [self CreatNewLabel:self.huoLabel title:@"或" color:Color.stub font:Common_Font(14)];
        [self.huoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.mas_bottom).offset(-84);
            make.centerX.mas_equalTo(self.mas_centerX);
            make.size.mas_equalTo(CGSizeMake(20, 14));
        }];
        //weixin
        self.wxLogoView = [UIImageView new];
        self.wxLogoView.image = [UIImage imageNamed:@"kuaijie_weixin"];
        [self addSubview:self.wxLogoView];
        //qq
        self.qqLogoView = [UIImageView new];
        self.qqLogoView.image = [UIImage imageNamed:@"kuaijie_QQ"];
        [self addSubview:self.qqLogoView];
        //weibo
        self.wbLogoView = [UIImageView new];
        self.wbLogoView.image = [UIImage imageNamed:@"kuaijie_weibo"];
        [self addSubview:self.wbLogoView];
        
        //分割线
        UIView *lineV1 = [[UIView alloc]init];
        lineV1.backgroundColor = Color.line;
        [self.quickBackView addSubview:lineV1];
        UIView *lineV2 = [[UIView alloc]init];
        lineV2.backgroundColor = Color.line;
        [self.accountBackView addSubview:lineV2];
        UIView *lineV3 = [[UIView alloc]init];
        lineV3.backgroundColor = Color.line;
        [self addSubview:lineV3];
        UIView *lineV4 = [[UIView alloc]init];
        lineV4.backgroundColor = Color.line;
        [self addSubview:lineV4];
        [lineV1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.phoneView.mas_bottom);
            make.left.mas_equalTo(self.quickBackView.mas_left).offset(30);
            make.height.mas_equalTo(1);
            make.right.mas_equalTo(self.quickBackView.mas_right).offset(-30);
        }];
        [lineV2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.accountView.mas_bottom);
            make.left.mas_equalTo(self.accountBackView.mas_left).offset(30);
            make.height.mas_equalTo(1);
            make.right.mas_equalTo(self.accountBackView.mas_right).offset(-30);
        }];
        [lineV3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_bottom).offset(-91);
            make.left.mas_equalTo(self.mas_left).offset(15);
            make.height.mas_equalTo(1);
            make.right.mas_equalTo(self.huoLabel.mas_left).offset(-15);
        }];
        [lineV4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_bottom).offset(-91);
            make.left.mas_equalTo(self.huoLabel.mas_right).offset(15);
            make.height.mas_equalTo(1);
            make.right.mas_equalTo(self.mas_right).offset(-15);
        }];
        
        UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(regist)];
        [self.registTapView addGestureRecognizer:tapGr];
    }
    return self;
}

-(void)CreatNewLabel:(UILabel *)label title:(NSString *)title color:(UIColor *)color font :(UIFont *)font{
    label.text = title;
    label.userInteractionEnabled = YES;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = color;
    label.font = font;
}

-(void)layoutSubviews{
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top);
        make.left.mas_equalTo(self.mas_left);
        make.size.mas_equalTo(CGSizeMake(kScreenW, 241));
    }];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.headerView.mas_bottom).offset(-90);
        make.centerX.mas_equalTo(self.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(90, 90));
    }];
    [self.quickLoginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headerView.mas_bottom).offset(-45);
        make.left.mas_equalTo(self.headerView.mas_left);
        make.size.mas_equalTo(CGSizeMake(kScreenW/2, 18));
    }];
    [self.accountLoginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headerView.mas_bottom).offset(-45);
        make.right.mas_equalTo(self.headerView.mas_right);
        make.size.mas_equalTo(CGSizeMake(kScreenW/2, 18));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.codeView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(90, 30));
        make.right.mas_equalTo(self.quickBackView.mas_right).offset(-30);
    }];
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.scrollView.mas_bottom).offset(10);
        make.left.mas_equalTo(self.mas_left).offset(15);
        make.right.mas_equalTo(self.mas_right).offset(-15);
        make.height.mas_equalTo(44);
    }];
    [self.goRegistView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.loginBtn.mas_bottom).offset(36);
        make.right.mas_equalTo(self.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(22, 15));
    }];
    [self.goRegistLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.loginBtn.mas_bottom).offset(36);
        make.right.mas_equalTo(self.goRegistView.mas_left).offset(-10);
        make.size.mas_equalTo(CGSizeMake(75, 15));
    }];
    [self.registTapView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.goRegistView.mas_centerY);
        make.right.mas_equalTo(self.goRegistView.mas_right);
        make.left.mas_equalTo(self.goRegistLabel.mas_left);
        make.height.mas_equalTo(30);
    }];
    [self.wxLogoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.mas_bottom).offset(-33.5);
        make.centerX.mas_equalTo(self.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
    [self.qqLogoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.mas_bottom).offset(-33.5);
        make.right.mas_equalTo(self.wxLogoView.mas_left).offset(-60);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
    [self.wbLogoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.mas_bottom).offset(-33.5);
        make.left.mas_equalTo(self.wxLogoView.mas_right).offset(60);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
}

- (void)regist{
    if ([self.delegate respondsToSelector:@selector(userChoose:)]) {
        [self.delegate userChoose:9];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
